package com.example.spring_ioc;

import com.example.spring_ioc.Component.UserComponent;
import com.example.spring_ioc.Controller.UserController;
import com.example.spring_ioc.model.UserInfo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;

//@ComponentScan("com.example.spring_ioc")
@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        // ApplicationContext 就是一个容器,注解创建的对象都可以从这里获取
        ApplicationContext context=SpringApplication.run(Application.class, args);
//        UserController bean = context.getBean(UserController.class);// 这个获取对象的方式底层原理就是反射机制
//        bean.say();
//        System.out.println(bean);
//
//        // 通过名字获取Bean的方式返回值是Object类型,需要强转一下
//        UserController userController=(UserController)context.getBean("userController");// 根据名称获得Bean对象
//        userController.say();
//        System.out.println(userController);
//
//        UserController bean1 = context.getBean("userController", UserController.class);
//        bean1.say();// 参数既有名字又有类对象,不需要强转
//        System.out.println(bean1);

//        UserService bean = context.getBean(UserService.class);
//        bean.say();

//        UserRepository bean = context.getBean(UserRepository.class);
//        bean.say();
//
//        UserComponent bean1 = context.getBean(UserComponent.class);
//        bean1.say();
//
//        UserConfiguration bean2 = context.getBean(UserConfiguration.class);
//        bean2.say();

//        UserInfo bean = context.getBean(UserInfo.class);
//        UserInfo userInfo = (UserInfo)context.getBean("zhangsan");
//        System.out.println(userInfo);// @Data 注解帮我们加上了toString方法,因此打印出来的不是地址




    }

}
